
#include "ui_image/ui_image.h"
#ifdef __cplusplus
extern "C" {
#endif

 
//窗体对象
static lv_obj_t * startUp_win = NULL;
static lv_obj_t * main_win = NULL;

 //主界面下 Time的位置
static lv_obj_t* imgTimeLocal_0 =NULL;
static lv_obj_t* imgTimeLocal_1 =NULL;
static lv_obj_t* imgTimeLocal_2 =NULL;
static lv_obj_t* imgTimeLocal_3 =NULL;

//心跳
static lv_obj_t* imgHeartBeat =NULL;//
static lv_obj_t* imgHeartButtom =NULL;//
static lv_obj_t* txtHeartBeat =NULL;//
//friend
static lv_obj_t* imgFriendButtom =NULL;//
static lv_obj_t* imgGoodFriend =NULL;//
static lv_obj_t* txtGoodFriend =NULL;//

const lv_img_dsc_t* timeNum[10]={
    &timeNum0,&timeNum1,&timeNum2,&timeNum3,&timeNum4,
    &timeNum5,&timeNum6,&timeNum7,&timeNum8,&timeNum9,
};


//初始化一些关键变量 通用变量--TODO整理成独立文件
void gui_Demo_init(void)
{

}



//启动界面 - GIF
 void gui_startUp_win_create(lv_obj_t * parent)
{
	//创建窗体
	startUp_win = parent;//屏幕对象用来模拟窗体
    if(startUp_win == NULL ) return;
	//创建启动界面图片
	lv_obj_t * gif_img = lv_gif_create(startUp_win);
    lv_gif_set_src(gif_img, &startUpGif);
    lv_obj_align(gif_img, LV_ALIGN_CENTER, 0, 0);
}

//在主界面显示时间
static void gui_main_win_showTime(unsigned short time)
{
    if(imgTimeLocal_2 == NULL)return;
    lv_img_set_src(imgTimeLocal_0, timeNum[time%10]);
    lv_img_set_src(imgTimeLocal_1, timeNum[(time/10)%10]);
    lv_img_set_src(imgTimeLocal_2, timeNum[(time/100)%10]);
    lv_img_set_src(imgTimeLocal_3, timeNum[(time/1000)%10]);
}

//创建主界面
 void gui_main_win_create(lv_obj_t * parent)
{
	//创建窗体
	main_win = parent;//用来模拟窗体
     
	if(main_win == NULL ) return;

	//创建一个界面 - 全黑底
	lv_obj_t * main_img = lv_img_create(main_win);
	lv_img_set_src(main_img,&blackButtom);//设置图片源
    lv_obj_set_size(main_img, 240, 240); // 设置对象大小
    lv_obj_center(main_img); // 对象居中显示

    //绘制主界面
    //创建Time对象
    imgTimeLocal_0 = lv_img_create(main_win);
    lv_obj_set_size(imgTimeLocal_0, 56, 64);
    lv_obj_align(imgTimeLocal_0, LV_ALIGN_CENTER, -60, -38);

    imgTimeLocal_1 = lv_img_create(main_win);
    lv_obj_set_size(imgTimeLocal_1, 56, 64);
    lv_obj_align(imgTimeLocal_1, LV_ALIGN_CENTER, -4, -38);

    imgTimeLocal_2 = lv_img_create(main_win);
    lv_obj_set_size(imgTimeLocal_2, 56, 64);
    lv_obj_align(imgTimeLocal_2, LV_ALIGN_CENTER, -60, 42);

    imgTimeLocal_3 = lv_img_create(main_win);
    lv_obj_set_size(imgTimeLocal_3, 56, 64);
    lv_obj_align(imgTimeLocal_3, LV_ALIGN_CENTER, -4, 42);

    //好感度
    imgHeartButtom = lv_img_create(main_win);
    lv_obj_set_size(imgHeartButtom, 50, 50);
    lv_obj_align(imgHeartButtom, LV_ALIGN_CENTER, 75, 39);

    //红色心
    imgHeartBeat = lv_img_create(imgHeartButtom);
    lv_obj_set_size(imgHeartBeat, 27, 21);
    lv_obj_align(imgHeartBeat, LV_ALIGN_CENTER, 0, -6);

    txtHeartBeat =lv_label_create(imgHeartButtom);//创建label
    lv_label_set_recolor(txtHeartBeat, true);
    lv_obj_align(txtHeartBeat, LV_ALIGN_CENTER, 5, 13);
    lv_obj_set_size(txtHeartBeat,16,16);//设定大小
    lv_label_set_text(txtHeartBeat, "#ffffff 0#");           //字体颜色


    //好友蓝色框
    imgFriendButtom = lv_img_create(main_win);
    lv_obj_set_size(imgFriendButtom, 50, 50);
    lv_obj_align(imgFriendButtom, LV_ALIGN_CENTER, 75, -21);

    //好友
    imgGoodFriend = lv_img_create(imgFriendButtom);
    lv_obj_set_size(imgGoodFriend, 27, 21);
    lv_obj_align(imgGoodFriend, LV_ALIGN_CENTER, 0, -6);

    txtGoodFriend =lv_label_create(imgFriendButtom);//创建label
    lv_label_set_recolor(txtGoodFriend, true);
    lv_obj_align(txtGoodFriend, LV_ALIGN_CENTER, 5, 13);
    lv_obj_set_size(txtGoodFriend,16,16);//设定大小
    lv_label_set_text(txtGoodFriend, "#ffffff 0#");           //字体颜色

    //
    gui_main_win_showTime(1234);
    lv_img_set_src(imgHeartButtom,&heartButtom  );
    lv_img_set_src(imgHeartBeat,&heartbeat  );
    lv_img_set_src(imgFriendButtom,&FriendButtom  );
    lv_img_set_src(imgGoodFriend,&goodFriend  );
}

//删除主界面
 void gui_main_win_dele(void)
 {
    if(main_win == NULL ) return;
    lv_obj_del(main_win);
    main_win =  NULL;
    imgTimeLocal_2 = NULL;
 }

const char* colorChange[] ={
"#ffffff 0#","#ffffff 1#","#ffffff 2#","#ffffff 3#","#ffffff 4#",
"#ffffff 5#","#ffffff 6#","#ffffff 7#","#ffffff 8#","#ffffff 9#",
} ;
static unsigned char heartCnt = 0,friendCnt = 0;
 void gui_main_win_run(void)
{
    static unsigned short cnt = 0,imgCnt = 0,flag = 0;
    if(cnt++<3)return;
    cnt = 0;

    if(main_win == NULL ) return;
    if(imgCnt++>= 9)imgCnt = 0;
    switch(flag++){
        case 0:
            if(heartCnt++>= 9)heartCnt = 0;
            lv_obj_clear_flag(imgHeartBeat, LV_OBJ_FLAG_HIDDEN);
            lv_label_set_text(txtHeartBeat,  colorChange[heartCnt]);           //字体颜色
            lv_img_set_src(imgTimeLocal_0, timeNum[imgCnt]);
        break;

        case 1:
             if(friendCnt++>= 9)friendCnt = 0;
            lv_obj_clear_flag(imgGoodFriend, LV_OBJ_FLAG_HIDDEN);
            lv_label_set_text(txtGoodFriend,  colorChange[friendCnt]);           //字体颜色
            lv_img_set_src(imgTimeLocal_1, timeNum[imgCnt]);
        break;

        case 2:
            lv_obj_add_flag(imgHeartBeat, LV_OBJ_FLAG_HIDDEN);
            lv_img_set_src(imgTimeLocal_2, timeNum[imgCnt]);
        break;

        case 3:
            lv_obj_add_flag(imgGoodFriend, LV_OBJ_FLAG_HIDDEN);
            lv_img_set_src(imgTimeLocal_3, timeNum[imgCnt]);
            flag=0;
        break;

        default:

        break;
    }
}


#ifdef __cplusplus
}
#endif
